package com.yunhe.rentcars.pro.controller.returncar;

import com.yunhe.rentcars.commons.dto.JSONResponse;
import com.yunhe.rentcars.commons.dto.Pageable;
import com.yunhe.rentcars.pro.entity.permi.Permission;
import com.yunhe.rentcars.pro.entity.rent.CarOrder;
import com.yunhe.rentcars.pro.entity.rent.Cars;
import com.yunhe.rentcars.pro.service.car.CarsService;
import com.yunhe.rentcars.pro.service.rent.CarOrderService;
import com.yunhe.rentcars.pro.service.rent.YuDingCarService;
import com.yunhe.rentcars.pro.service.returncar.ReturncarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/28 0028.
 */
@Controller
@RequestMapping("/returncar")
public class ReturnCarController {

    @Autowired
    private ReturncarService returncarService;

    @Autowired
    private CarOrderService carOrderService;

    @Autowired
    private CarsService carsService;


    @RequestMapping
    public String list(){
        return "returncar/list";
    }

    @RequestMapping("/listData")
    @ResponseBody
    public Pageable list(Integer offset, Integer limit,String orderid,String mobile){
        Pageable<CarOrder> pageable = returncarService.findList(offset, limit, orderid, mobile);
        return pageable;
    }



    @RequestMapping("/returnSearch")
    @ResponseBody
    public JSONResponse returnSearch(String orderid){
        List list = new ArrayList();
        CarOrder carOrder = carOrderService.findCarOrder(null, orderid);
        if(null != carOrder){
            Cars cars = carsService.findOne(carOrder.getCarid(), null);
            list.add(cars);
            list.add(carOrder);
            return JSONResponse.success("",list);
        }else{
            return JSONResponse.fail("订单查询失败");
        }
    }

    @RequestMapping("/returnregister")

    public String returnregister(){
       return "returncar/returnregister";
    }

    @RequestMapping("/returncheck")
    public String payOrder(Long id,Long carid,HttpServletRequest req){
        CarOrder carOrder = carOrderService.findCarOrder(id,null);
        Cars cars = carsService.findOne(carid, null);
        req.setAttribute("carOrder",carOrder);
        req.setAttribute("cars",cars);
        return "returncar/returncheck";
    }

}
